
package com.sec.android.app.myfiles.thumbnail;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.sec.android.app.myfiles.module.abstraction.FileRecord;

public class MemoryCacheMgr implements AbsCacheMgr {
    private static LruCache<Object, Bitmap> sCache;
    private static MemoryCacheMgr mInstance = null;
    
    private static int cacheCnt = 64;

    private MemoryCacheMgr() {
        sCache = new LruCache<Object, Bitmap>(cacheCnt);
    }

    public static synchronized MemoryCacheMgr getInstance() {
        if (mInstance == null) {
            mInstance = new MemoryCacheMgr();
        }
        return mInstance;
    }

    @Override
    public void addCache(FileRecord record, Bitmap bmp) {
        sCache.put(record.getKey(), bmp);
    }

    public void clearCache() {
        sCache.evictAll();
    }

    @Override
    public Bitmap getCache(FileRecord record) {
        return sCache.get(record.getKey());
    }
}
